package com.it.config;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
public class MyConfig {


    @Bean
    public TransportClient client() throws UnknownHostException {
        //获取ip地址
        InetSocketTransportAddress net = new InetSocketTransportAddress(InetAddress.getByName("192.168.1.128"), 9300);
        //es集群名称获取
        Settings setting = Settings.builder().put("cluster.name", "wali").build();
        TransportClient client = new PreBuiltTransportClient(setting);
        client.addTransportAddress(net);
        return client;
    }
}
